<!DOCTYPE html>
<html lang="en">
<head>
    <div th:include="base-libs :: base-libs" />
    <meta charset="UTF-8">
    <title>新增/修改--机构协议模板</title>
    <script th:inline="javascript">
        /**读取request中的初始化数据*/
//        var requestData = [[${requestData}]];
        var XYMBID = [[${XYMBID}]];
        var XYMBMC = [[${XYMBMC}]];
    </script>
    <link th:href="@{/service/css/xymb.css}" rel="stylesheet"/>
    <script th:src="@{/service/js/xymb.js}"></script>
    
    <style>
    	.panel,.panel-header,.panel-body{
    		width:100% !important;
    	}
    </style>
    <script type="text/javascript">

        /*机构协议模板类型默认值 02*/
        var XYMBLX = "02";

        $(function () {
            initView();
            /*模板ID有值 则查询改模板配置的实例*/
            if(!StringUtils.isEmpty(XYMBID)){
                $("#XYMBMC").val(XYMBMC);
                $("#modelDiv").remove();
                $("body").data("XYMB", {XYMBID: XYMBID, XYMBMC: XYMBMC});
                $.QuickRemote.AjaxJson("queryXymb", function(result){
//                 	alert(JSON.stringify(result))
                    var content = result["CONTENT"];
                    $("#center").append(content);
                }, {XYMBID: XYMBID});
            }else{
                /*请求静态模板文件*/
                /*$.QuickRemote.AjaxXML("getTemplate", function(result){
                    var content = result["documentElement"];
                    content = $(content).prop("outerHTML");
                    $.parser.parse($("#center").append(content));
                }, {template: "template-02-01"});*/
            }
        })

        function initView(){
        	initDeleteFwxMethod();
        }

        /** 保存协议模板 */
        function btnSaveHandler(){
            if($("#XYMBMC,.dynamicText").QuickValidate()){
                $(".dynamicText").each(function(){
                    $(this).text($(this).val());
                });
                var XYMB = $("body").data("XYMB");
                if(!XYMB){
                    XYMB = {XYMBLX: XYMBLX};
                }
                var content = $(".xymbContent").prop("outerHTML");
                /*协议页面*/
                XYMB["CONTENT"] = content;
                var FWIDS = getFwids();
                /*关联服务项*/
                XYMB["FWIDS"] = FWIDS;
                var XYMBMC = $("#XYMBMC").val();
                /*协议模板名称*/
                XYMB["XYMBMC"] = XYMBMC;
                $.QuickRemote.AjaxJson(contextRoot + "xymb/save", saveHandler, XYMB);
            }
        }

        /** 保存协议回调 */
        function saveHandler(result){
            if (result["state"]) {
                $.QuickAlert.alertNormal("保存成功",{callback: function(){
                    btnBackHandler()
                }});
            } else {
                $.QuickAlert.alertFail({
                    content : result.info["faultInfo"]
                });
            }
        }
        
        /**返回按钮*/
        function btnBackHandler(){
            $.QuickUrlUtils.back();
        }
    </script>
</head>
<body class="easyui-layout">
<div region="north" style="height: 41px; border: none; overflow: hidden; background-color: #f9f9f9;">
    <div class="title">
        <h3>机构协议模板</h3>
    </div>
</div>
<div id="center" region="center" style="overflow: auto;">
    <div style="background-color: #FFF;">
        <table class="form-table" style="margin-bottom: 2px;">
            <tr>
                <td class="td-text">
                    <label>协议模板名称：</label>
                </td>
                <td>
                    <input id="XYMBMC" name="XYMBMC" style="padding-left: 4px;" class="form-control"
                           quick-config="label:'协议模板名称', validateProxy:'notNull length', length: '50'">
                </td>
            </tr>
        </table>
    </div>
    <div th:include="xymb/template-02-01 :: template-02-01" id="modelDiv"></div>
</div>
<div region="south" style="height: 41px; border: none; overflow: hidden; background-color: #f9f9f9; padding-top: 6px; text-align: center;">
    <button id="btnSave" type="button" onclick="btnSaveHandler()" style=" margin-left: 10px;">保存</button>
    <button id="btnBack" type="button" onclick="btnBackHandler()" style=" margin-left: 10px;">返回</button>
</div>
</body>
<script type="text/html" id="trFwx">
    <tr>
        <td>
            <span name="XH">1</span>
            <span name="FWID" style="display: none;"></span>
        </td>
        <td>
            <span name="FWMC"></span>
        </td>
        <td>
            <span name="FWNR"></span>
        </td>
        <td>
            <a class="trFwxBtn">移除</a>
        </td>
    </tr>
</script>
</html>